﻿// Wantn.Share.RandSampling
using System;
using System.Collections.Generic;

namespace Wantn.Share
{
    public sealed class RandSampling
    {
        public static List<T> Make<T>(List<T> population, int sampleCount, bool duplicate) where T : IComparable<T>
        {
            if (population != null && population.Count >= 1)
            {
                if (sampleCount <= 0)
                {
                    throw new ApplicationException("抽样个数必须大于0");
                }
                if (sampleCount > population.Count)
                {
                    throw new ApplicationException("抽样个数大于抽样母体的数据个数");
                }
                List<T> list = new List<T>();
                List<T> list2 = new List<T>(population);
                Class1 @class = new Class2(Guid.NewGuid().GetHashCode());
                for (int i = 1; i <= sampleCount; i++)
                {
                    int index = @class.vmethod_3(list2.Count);
                    list.Add(list2[index]);
                    if (!duplicate)
                    {
                        list2.RemoveAt(index);
                    }
                }
                list.Sort();
                return list;
            }
            throw new ApplicationException("抽样母体的数据个数必须大于0");
        }

    }
}
